{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "collapsed_sections": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU",
    "widgets": {
      "application/vnd.jupyter.widget-state+json": {
        "0f8bcc7cd8dd420490ef846159005f9f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HBoxModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "HBoxModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "HBoxView",
            "box_style": "",
            "children": [
              "IPY_MODEL_e33327ae13474e179a2642cdcff3ffe1",
              "IPY_MODEL_ed11c6e29c6d410abf6553233c942dca",
              "IPY_MODEL_1c4809dd7c72473096edcaa61711334f"
            ],
            "layout": "IPY_MODEL_116d47570e7b44389bf8972434cafb6c"
          }
        },
        "e33327ae13474e179a2642cdcff3ffe1": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "HTMLModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "HTMLView",
            "description": "",
            "description_tooltip": null,
            "layout": "IPY_MODEL_e3b0e410eef24301b220d2761fc3f79c",
            "placeholder": "​",
            "style": "IPY_MODEL_b4ed1dc3907140ff96eecd370ec3edb4",
            "value": ""
          }
        },
        "ed11c6e29c6d410abf6553233c942dca": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "FloatProgressModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "FloatProgressModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "ProgressView",
            "bar_style": "success",
            "description": "",
            "description_tooltip": null,
            "layout": "IPY_MODEL_1e9ded61935943ed942e9df4a9f54d5b",
            "max": 1,
            "min": 0,
            "orientation": "horizontal",
            "style": "IPY_MODEL_11cc9d4697dc4db8bdacdaea8f1ebf72",
            "value": 0
          }
        },
        "1c4809dd7c72473096edcaa61711334f": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "HTMLModel",
          "model_module_version": "1.5.0",
          "state": {
            "_dom_classes": [],
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "HTMLModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/controls",
            "_view_module_version": "1.5.0",
            "_view_name": "HTMLView",
            "description": "",
            "description_tooltip": null,
            "layout": "IPY_MODEL_cfae07c313334cb493fce36d5f276889",
            "placeholder": "​",
            "style": "IPY_MODEL_f69fcdd6971a4147988cf12d9f98325b",
            "value": " 0/0 [00:00&lt;?, ?it/s]"
          }
        },
        "116d47570e7b44389bf8972434cafb6c": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": null
          }
        },
        "e3b0e410eef24301b220d2761fc3f79c": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": null
          }
        },
        "b4ed1dc3907140ff96eecd370ec3edb4": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "DescriptionStyleModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "StyleView",
            "description_width": ""
          }
        },
        "1e9ded61935943ed942e9df4a9f54d5b": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": "20px"
          }
        },
        "11cc9d4697dc4db8bdacdaea8f1ebf72": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "ProgressStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "ProgressStyleModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "StyleView",
            "bar_color": null,
            "description_width": ""
          }
        },
        "cfae07c313334cb493fce36d5f276889": {
          "model_module": "@jupyter-widgets/base",
          "model_name": "LayoutModel",
          "model_module_version": "1.2.0",
          "state": {
            "_model_module": "@jupyter-widgets/base",
            "_model_module_version": "1.2.0",
            "_model_name": "LayoutModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "LayoutView",
            "align_content": null,
            "align_items": null,
            "align_self": null,
            "border": null,
            "bottom": null,
            "display": null,
            "flex": null,
            "flex_flow": null,
            "grid_area": null,
            "grid_auto_columns": null,
            "grid_auto_flow": null,
            "grid_auto_rows": null,
            "grid_column": null,
            "grid_gap": null,
            "grid_row": null,
            "grid_template_areas": null,
            "grid_template_columns": null,
            "grid_template_rows": null,
            "height": null,
            "justify_content": null,
            "justify_items": null,
            "left": null,
            "margin": null,
            "max_height": null,
            "max_width": null,
            "min_height": null,
            "min_width": null,
            "object_fit": null,
            "object_position": null,
            "order": null,
            "overflow": null,
            "overflow_x": null,
            "overflow_y": null,
            "padding": null,
            "right": null,
            "top": null,
            "visibility": null,
            "width": null
          }
        },
        "f69fcdd6971a4147988cf12d9f98325b": {
          "model_module": "@jupyter-widgets/controls",
          "model_name": "DescriptionStyleModel",
          "model_module_version": "1.5.0",
          "state": {
            "_model_module": "@jupyter-widgets/controls",
            "_model_module_version": "1.5.0",
            "_model_name": "DescriptionStyleModel",
            "_view_count": null,
            "_view_module": "@jupyter-widgets/base",
            "_view_module_version": "1.2.0",
            "_view_name": "StyleView",
            "description_width": ""
          }
        }
      }
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "### Download Whisper"
      ],
      "metadata": {
        "id": "oz0vA1nAW8O6"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#避免Colab断开连接的方法：\n",
        "#在网页内按键Ctrl+Shift+I，跳到控制台界面，输入以下的内容：\n",
        "#function ConnectButton(){\n",
        "    #console.log(\"Connect pushed\"); \n",
        "    #document.querySelector(\"#top-toolbar > colab-connect-button\").shadowRoot.querySelector(\"#connect\").click()}\n",
        "#setInterval(ConnectButton,60000);\n",
        "#记得删掉前面的#"
      ],
      "metadata": {
        "id": "w62ZGgAnxwe5"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!git clone https://github.com/AlexandaJerry/whisper-vits-japanese"
      ],
      "metadata": {
        "id": "No9FcLh6W9UL",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "f24bac4e-6a0c-40de-d63e-0d63156fe41b"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Cloning into 'whisper-vits-japanese'...\n",
            "remote: Enumerating objects: 135, done.\u001b[K\n",
            "remote: Counting objects: 100% (27/27), done.\u001b[K\n",
            "remote: Compressing objects: 100% (22/22), done.\u001b[K\n",
            "remote: Total 135 (delta 7), reused 12 (delta 3), pack-reused 108\u001b[K\n",
            "Receiving objects: 100% (135/135), 43.80 MiB | 22.73 MiB/s, done.\n",
            "Resolving deltas: 100% (13/13), done.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%%capture\n",
        "!pip install git+https://github.com/openai/whisper.git"
      ],
      "metadata": {
        "id": "FXy7Qki0ArCs"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "!cp -r /content/whisper-vits-japanese/whisper/transcribe.py /usr/local/lib/python3.7/dist-packages/whisper\n",
        "!cp -r /content/whisper-vits-japanese/whisper/utils.py /usr/local/lib/python3.7/dist-packages/whisper"
      ],
      "metadata": {
        "id": "OBQpIxEWXUAf"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import whisper"
      ],
      "metadata": {
        "id": "f3nrt2LIXVD-",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 104,
          "referenced_widgets": [
            "0f8bcc7cd8dd420490ef846159005f9f",
            "e33327ae13474e179a2642cdcff3ffe1",
            "ed11c6e29c6d410abf6553233c942dca",
            "1c4809dd7c72473096edcaa61711334f",
            "116d47570e7b44389bf8972434cafb6c",
            "e3b0e410eef24301b220d2761fc3f79c",
            "b4ed1dc3907140ff96eecd370ec3edb4",
            "1e9ded61935943ed942e9df4a9f54d5b",
            "11cc9d4697dc4db8bdacdaea8f1ebf72",
            "cfae07c313334cb493fce36d5f276889",
            "f69fcdd6971a4147988cf12d9f98325b"
          ]
        },
        "outputId": "3044495d-5ec8-4d36-9a6d-77baa74b4458"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "The cache for model files in Transformers v4.22.0 has been updated. Migrating your old cache. This is a one-time only operation. You can interrupt this and resume the migration later on by calling `transformers.utils.move_cache()`.\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Moving 0 files to the new cache system\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "0it [00:00, ?it/s]"
            ],
            "application/vnd.jupyter.widget-view+json": {
              "version_major": 2,
              "version_minor": 0,
              "model_id": "0f8bcc7cd8dd420490ef846159005f9f"
            }
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Prepare Data for Whisper ASR"
      ],
      "metadata": {
        "id": "nTukkE9NXIoY"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "metadata": {
        "id": "yWSW8Ml8MX2W"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "###此处是唯一需要自己改动的地方：自己的音频zip路径"
      ],
      "metadata": {
        "id": "yrF3iDQ_kIgS"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#目前支持日语，换成别语言需替换text文件夹cleaner和symbols以及config文件夹中isla_base.json的cleaner参数\n",
        "#这里只需用新路径替换掉/content/drive/MyDrive/isla_base/isla.zip即可(音频需为wav)\n",
        "!unzip -j /content/drive/MyDrive/isla_base/isla.zip \"*/*.wav\" -d /content/whisper-vits-japanese/audio"
      ],
      "metadata": {
        "id": "zfaaUxXYVKNN"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#如果没有训练数据只想体验的话，这里只能暂时借用下White老师的数据集了，作为入门材料真是万分感谢\n",
        "%cd /content/whisper-vits-japanese\n",
        "!wget --load-cookies /tmp/cookies.txt \"https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1H6aqdGP-h-MT7XAVk870Ql4d3QrJT-7o' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\\1\\n/p')&id=1H6aqdGP-h-MT7XAVk870Ql4d3QrJT-7o\" -O \"isla.zip\" && rm -rf /tmp/cookies.txt\n",
        "!unzip -j /content/whisper-vits-japanese/isla.zip \"*/*.wav\" -d /content/whisper-vits-japanese/audio"
      ],
      "metadata": {
        "id": "Lfl3Jx7rg0cj"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#识别过程总共花费50分钟(大概是音频总长的三分之一到一半左右)\n",
        "!whisper -i /content/whisper-vits-japanese/audio -o /content/whisper-vits-japanese/srt_files --language Japanese"
      ],
      "metadata": {
        "id": "rmLdedLvSAcC"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#auto.py会根据Whisper导出的srt自动切片音频、转写文本、转采样率为22050HZ\n",
        "#最后会把适配VIST的数据格式汇总在/content/whisper-vits-japanese/filelists\n",
        "#然后音频数据会被放在/content/whisper-vits-japanese/sliced_audio文件夹里\n",
        "!pip install pydub\n",
        "%cd /content/whisper-vits-japanese\n",
        "!python auto.py"
      ],
      "metadata": {
        "id": "TT1IPemlfnMe"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Install Requirements of VITS"
      ],
      "metadata": {
        "id": "EIQTfLHyV-md"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install -r requirements.txt\n",
        "!sudo apt-get install espeak -y"
      ],
      "metadata": {
        "id": "Z0qEu4ftO9N3"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Alignment and Text Conversion"
      ],
      "metadata": {
        "id": "lmEwZSRJPJbo"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "path = \"/content/whisper-vits-japanese\"\n",
        "os.chdir(path)\n",
        "print(os.getcwd())"
      ],
      "metadata": {
        "id": "ym67KvqlV1DH",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "db7c9b42-3089-4ef7-d9e4-f27c394e17a8"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/whisper-vits-japanese\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%cd monotonic_align\n",
        "!python setup.py build_ext --inplace\n",
        "%cd .."
      ],
      "metadata": {
        "id": "8c2xU9XPH7K_"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "path = \"/content/whisper-vits-japanese\"\n",
        "os.chdir(path)\n",
        "print(os.getcwd())"
      ],
      "metadata": {
        "id": "kYWFPADJWDxD",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "b7e8fff2-74be-49fb-f6a4-4b7759dacde8"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/whisper-vits-japanese\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#如果输出提示nophoneme这种情况，检查下/content/whisper-vits-japanese/filelists的两个txt文件里有没有出现英文转写\n",
        "!python preprocess.py --text_index 1 --text_cleaners japanese_cleaners --filelists /content/whisper-vits-japanese/filelists/train_filelist.txt /content/whisper-vits-japanese/filelists/val_filelist.txt"
      ],
      "metadata": {
        "id": "2NNNMdYHWGjx",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "59fc8f5c-d358-46eb-a0ce-794cf750c6e2"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "START: /content/whisper-vits-japanese/filelists/train_filelist.txt\n",
            "Downloading: \"https://github.com/r9y9/open_jtalk/releases/download/v1.11.1/open_jtalk_dic_utf_8-1.11.tar.gz\"\n",
            "dic.tar.gz: 100% 22.6M/22.6M [00:02<00:00, 10.9MB/s]\n",
            "Extracting tar file /usr/local/lib/python3.7/dist-packages/pyopenjtalk/dic.tar.gz\n",
            "START: /content/whisper-vits-japanese/filelists/val_filelist.txt\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Train"
      ],
      "metadata": {
        "id": "IVWRcdtdWY5M"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "!python train.py -c configs/isla_base.json -m isla_base"
      ],
      "metadata": {
        "id": "JXhkRuxQWV-Y"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Inference"
      ],
      "metadata": {
        "id": "muChqfiKWg1x"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#如果出现大批量的log日志显示在输出的话\n",
        "#在\"代码执行程序\"下拉菜单选择\"重新启动代码程序\"\n",
        "#再从该代码框开始，重新运行进行推断和输出语音\n",
        "import os\n",
        "path = \"/content/whisper-vits-japanese\"\n",
        "os.chdir(path)\n",
        "print(os.getcwd())\n",
        "\n",
        "%matplotlib inline\n",
        "import matplotlib.pyplot as plt\n",
        "import IPython.display as ipd\n",
        "\n",
        "import os\n",
        "import json\n",
        "import math\n",
        "import torch\n",
        "from torch import nn\n",
        "from torch.nn import functional as F\n",
        "from torch.utils.data import DataLoader\n",
        "\n",
        "import commons\n",
        "import utils\n",
        "from data_utils import TextAudioLoader, TextAudioCollate, TextAudioSpeakerLoader, TextAudioSpeakerCollate\n",
        "from models import SynthesizerTrn\n",
        "from text.symbols import symbols\n",
        "from text import text_to_sequence\n",
        "\n",
        "from scipy.io.wavfile import write\n",
        "\n",
        "\n",
        "def get_text(text, hps):\n",
        "    text_norm = text_to_sequence(text, hps.data.text_cleaners)\n",
        "    if hps.data.add_blank:\n",
        "        text_norm = commons.intersperse(text_norm, 0)\n",
        "    text_norm = torch.LongTensor(text_norm)\n",
        "    return text_norm"
      ],
      "metadata": {
        "id": "N_s3vd9jWdC8",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "504e71e9-8730-4d8b-bf05-fedaf9cf3275"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/whisper-vits-japanese\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "hps = utils.get_hparams_from_file(\"/content/whisper-vits-japanese/configs/isla_base.json\")"
      ],
      "metadata": {
        "id": "kDwA3fWlWj9s"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "net_g = SynthesizerTrn(\n",
        "    len(symbols),\n",
        "    hps.data.filter_length // 2 + 1,\n",
        "    hps.train.segment_size // hps.data.hop_length,\n",
        "    **hps.model).cuda()\n",
        "_ = net_g.eval()\n",
        "\n",
        "#下面的这个isla_base/G_6000.pth需要换成目标文件夹里数字最大的G_????.pth\n",
        "_ = utils.load_checkpoint(\"/content/whisper-vits-japanese/logs/isla_base/G_????.pth\", net_g, None)"
      ],
      "metadata": {
        "id": "J9pPjEkuWlyh"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "stn_tst = get_text(\"ビエザイゼリ…ーファーディエン\", hps) #别在这里发癫 停顿可用…、\n",
        "with torch.no_grad():\n",
        "    x_tst = stn_tst.cuda().unsqueeze(0)\n",
        "    x_tst_lengths = torch.LongTensor([stn_tst.size(0)]).cuda()\n",
        "    audio = net_g.infer(x_tst, x_tst_lengths, noise_scale=.667, noise_scale_w=0.8, length_scale=1)[0][0,0].data.cpu().float().numpy()\n",
        "ipd.display(ipd.Audio(audio, rate=hps.data.sampling_rate))"
      ],
      "metadata": {
        "id": "p3KH-j_GK8Cn"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Save Materials and Checkpoints to Drive for Future Usage"
      ],
      "metadata": {
        "id": "YnsPTT2ZBanL"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "#把checkpoint存入google drive(这里用了RT防止递归式复制到目标文件夹)\n",
        "!cp -RT /content/whisper-vits-japanese/logs/ /content/drive/MyDrive/logs/\n",
        "#把音频文件和对应抄本存入google drive\n",
        "!cp -RT /content/whisper-vits-japanese/sliced_audio/ /content/drive/MyDrive/sliced_audio/\n",
        "!cp -RT /content/whisper-vits-japanese/filelists/ /content/drive/MyDrive/filelists/"
      ],
      "metadata": {
        "id": "DJFCHUn0WnpX"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "### Restart from Lastest Checkpoint in the Next Time\n",
        "\n"
      ],
      "metadata": {
        "id": "svJVr6CtUwOE"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "metadata": {
        "id": "n-QRqLulUzHm",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "38e6debe-588d-4625-e570-3e84b11ca3f2"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Mounted at /content/drive\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!git clone https://github.com/AlexandaJerry/whisper-vits-japanese"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ap94qMooqM6d",
        "outputId": "b08e65b1-adbb-4952-db43-2fe4c258fe8f"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Cloning into 'whisper-vits-japanese'...\n",
            "remote: Enumerating objects: 138, done.\u001b[K\n",
            "remote: Counting objects: 100% (30/30), done.\u001b[K\n",
            "remote: Compressing objects: 100% (24/24), done.\u001b[K\n",
            "remote: Total 138 (delta 8), reused 15 (delta 4), pack-reused 108\u001b[K\n",
            "Receiving objects: 100% (138/138), 43.81 MiB | 33.68 MiB/s, done.\n",
            "Resolving deltas: 100% (14/14), done.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#把google drive的checkpoint恢复到文件夹\n",
        "!cp -r /content/drive/MyDrive/logs/** /content/whisper-vits-japanese/logs/\n",
        "#把音频文件和对应抄本恢复到文件夹\n",
        "!cp -r /content/drive/MyDrive/sliced_audio/** /content/whisper-vits-japanese/sliced_audio/\n",
        "!cp -r /content/drive/MyDrive/filelists/** /content/whisper-vits-japanese/filelists/"
      ],
      "metadata": {
        "id": "DYM1HFv4WqXg",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "c76f50d1-d590-4a29-989b-73ebb4a3f768"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "cp: target '/content/whisper-vits-japanese/logs/isla_base/' is not a directory\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "%cd /content/whisper-vits-japanese\n",
        "!pip install -r requirements.txt\n",
        "!sudo apt-get install espeak -y\n",
        "%cd monotonic_align\n",
        "!python setup.py build_ext --inplace\n",
        "%cd ..\n",
        "!python train.py -c configs/isla_base.json -m isla_base"
      ],
      "metadata": {
        "id": "vUwJbLK-Qn6r",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "61674493-57db-44fc-ebd4-c33e67081661"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/whisper-vits-japanese\n",
            "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
            "Collecting Cython==0.29.21\n",
            "  Downloading Cython-0.29.21-cp37-cp37m-manylinux1_x86_64.whl (2.0 MB)\n",
            "\u001b[K     |████████████████████████████████| 2.0 MB 5.2 MB/s \n",
            "\u001b[?25hCollecting librosa==0.8.0\n",
            "  Downloading librosa-0.8.0.tar.gz (183 kB)\n",
            "\u001b[K     |████████████████████████████████| 183 kB 60.8 MB/s \n",
            "\u001b[?25hCollecting matplotlib==3.3.1\n",
            "  Downloading matplotlib-3.3.1-cp37-cp37m-manylinux1_x86_64.whl (11.6 MB)\n",
            "\u001b[K     |████████████████████████████████| 11.6 MB 49.0 MB/s \n",
            "\u001b[?25hRequirement already satisfied: numpy==1.21.6 in /usr/local/lib/python3.7/dist-packages (from -r requirements.txt (line 4)) (1.21.6)\n",
            "Collecting phonemizer==2.2.1\n",
            "  Downloading phonemizer-2.2.1-py3-none-any.whl (49 kB)\n",
            "\u001b[K     |████████████████████████████████| 49 kB 6.3 MB/s \n",
            "\u001b[?25hCollecting scipy==1.5.2\n",
            "  Downloading scipy-1.5.2-cp37-cp37m-manylinux1_x86_64.whl (25.9 MB)\n",
            "\u001b[K     |████████████████████████████████| 25.9 MB 1.6 MB/s \n",
            "\u001b[?25hCollecting Unidecode==1.1.1\n",
            "  Downloading Unidecode-1.1.1-py2.py3-none-any.whl (238 kB)\n",
            "\u001b[K     |████████████████████████████████| 238 kB 38.5 MB/s \n",
            "\u001b[?25hCollecting pyopenjtalk==0.2.0\n",
            "  Downloading pyopenjtalk-0.2.0.tar.gz (1.5 MB)\n",
            "\u001b[K     |████████████████████████████████| 1.5 MB 55.7 MB/s \n",
            "\u001b[?25h  Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
            "  Getting requirements to build wheel ... \u001b[?25l\u001b[?25hdone\n",
            "    Preparing wheel metadata ... \u001b[?25l\u001b[?25hdone\n",
            "Requirement already satisfied: audioread>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (3.0.0)\n",
            "Requirement already satisfied: scikit-learn!=0.19.0,>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (1.0.2)\n",
            "Requirement already satisfied: joblib>=0.14 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (1.1.0)\n",
            "Requirement already satisfied: decorator>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (4.4.2)\n",
            "Requirement already satisfied: resampy>=0.2.2 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (0.4.0)\n",
            "Requirement already satisfied: numba>=0.43.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (0.56.2)\n",
            "Requirement already satisfied: soundfile>=0.9.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (0.10.3.post1)\n",
            "Requirement already satisfied: pooch>=1.0 in /usr/local/lib/python3.7/dist-packages (from librosa==0.8.0->-r requirements.txt (line 2)) (1.6.0)\n",
            "Requirement already satisfied: certifi>=2020.06.20 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.1->-r requirements.txt (line 3)) (2022.6.15)\n",
            "Requirement already satisfied: python-dateutil>=2.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.1->-r requirements.txt (line 3)) (2.8.2)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.1->-r requirements.txt (line 3)) (0.11.0)\n",
            "Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.1->-r requirements.txt (line 3)) (7.1.2)\n",
            "Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.1->-r requirements.txt (line 3)) (3.0.9)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib==3.3.1->-r requirements.txt (line 3)) (1.4.4)\n",
            "Collecting segments\n",
            "  Downloading segments-2.2.1-py2.py3-none-any.whl (15 kB)\n",
            "Requirement already satisfied: attrs>=18.1 in /usr/local/lib/python3.7/dist-packages (from phonemizer==2.2.1->-r requirements.txt (line 5)) (22.1.0)\n",
            "Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from pyopenjtalk==0.2.0->-r requirements.txt (line 8)) (1.15.0)\n",
            "Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from pyopenjtalk==0.2.0->-r requirements.txt (line 8)) (4.64.1)\n",
            "Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from kiwisolver>=1.0.1->matplotlib==3.3.1->-r requirements.txt (line 3)) (4.1.1)\n",
            "Requirement already satisfied: setuptools<60 in /usr/local/lib/python3.7/dist-packages (from numba>=0.43.0->librosa==0.8.0->-r requirements.txt (line 2)) (57.4.0)\n",
            "Requirement already satisfied: llvmlite<0.40,>=0.39.0dev0 in /usr/local/lib/python3.7/dist-packages (from numba>=0.43.0->librosa==0.8.0->-r requirements.txt (line 2)) (0.39.1)\n",
            "Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.7/dist-packages (from numba>=0.43.0->librosa==0.8.0->-r requirements.txt (line 2)) (4.12.0)\n",
            "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.7/dist-packages (from pooch>=1.0->librosa==0.8.0->-r requirements.txt (line 2)) (21.3)\n",
            "Requirement already satisfied: requests>=2.19.0 in /usr/local/lib/python3.7/dist-packages (from pooch>=1.0->librosa==0.8.0->-r requirements.txt (line 2)) (2.23.0)\n",
            "Requirement already satisfied: appdirs>=1.3.0 in /usr/local/lib/python3.7/dist-packages (from pooch>=1.0->librosa==0.8.0->-r requirements.txt (line 2)) (1.4.4)\n",
            "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->pooch>=1.0->librosa==0.8.0->-r requirements.txt (line 2)) (2.10)\n",
            "Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->pooch>=1.0->librosa==0.8.0->-r requirements.txt (line 2)) (3.0.4)\n",
            "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19.0->pooch>=1.0->librosa==0.8.0->-r requirements.txt (line 2)) (1.24.3)\n",
            "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn!=0.19.0,>=0.14.0->librosa==0.8.0->-r requirements.txt (line 2)) (3.1.0)\n",
            "Requirement already satisfied: cffi>=1.0 in /usr/local/lib/python3.7/dist-packages (from soundfile>=0.9.0->librosa==0.8.0->-r requirements.txt (line 2)) (1.15.1)\n",
            "Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi>=1.0->soundfile>=0.9.0->librosa==0.8.0->-r requirements.txt (line 2)) (2.21)\n",
            "Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata->numba>=0.43.0->librosa==0.8.0->-r requirements.txt (line 2)) (3.8.1)\n",
            "Requirement already satisfied: regex in /usr/local/lib/python3.7/dist-packages (from segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (2022.6.2)\n",
            "Collecting csvw>=1.5.6\n",
            "  Downloading csvw-3.1.1-py2.py3-none-any.whl (56 kB)\n",
            "\u001b[K     |████████████████████████████████| 56 kB 5.1 MB/s \n",
            "\u001b[?25hCollecting clldutils>=1.7.3\n",
            "  Downloading clldutils-3.12.0-py2.py3-none-any.whl (197 kB)\n",
            "\u001b[K     |████████████████████████████████| 197 kB 52.7 MB/s \n",
            "\u001b[?25hRequirement already satisfied: tabulate>=0.7.7 in /usr/local/lib/python3.7/dist-packages (from clldutils>=1.7.3->segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (0.8.10)\n",
            "Collecting colorlog\n",
            "  Downloading colorlog-6.7.0-py2.py3-none-any.whl (11 kB)\n",
            "Collecting rfc3986<2\n",
            "  Downloading rfc3986-1.5.0-py2.py3-none-any.whl (31 kB)\n",
            "Requirement already satisfied: uritemplate>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from csvw>=1.5.6->segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (3.0.1)\n",
            "Collecting language-tags\n",
            "  Downloading language_tags-1.1.0-py2.py3-none-any.whl (210 kB)\n",
            "\u001b[K     |████████████████████████████████| 210 kB 63.8 MB/s \n",
            "\u001b[?25hCollecting isodate\n",
            "  Downloading isodate-0.6.1-py2.py3-none-any.whl (41 kB)\n",
            "\u001b[K     |████████████████████████████████| 41 kB 714 kB/s \n",
            "\u001b[?25hCollecting rdflib\n",
            "  Downloading rdflib-6.2.0-py3-none-any.whl (500 kB)\n",
            "\u001b[K     |████████████████████████████████| 500 kB 62.8 MB/s \n",
            "\u001b[?25hCollecting colorama\n",
            "  Downloading colorama-0.4.5-py2.py3-none-any.whl (16 kB)\n",
            "Requirement already satisfied: jsonschema in /usr/local/lib/python3.7/dist-packages (from csvw>=1.5.6->segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (4.3.3)\n",
            "Requirement already satisfied: babel in /usr/local/lib/python3.7/dist-packages (from csvw>=1.5.6->segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (2.10.3)\n",
            "Requirement already satisfied: pytz>=2015.7 in /usr/local/lib/python3.7/dist-packages (from babel->csvw>=1.5.6->segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (2022.2.1)\n",
            "Requirement already satisfied: importlib-resources>=1.4.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema->csvw>=1.5.6->segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (5.9.0)\n",
            "Requirement already satisfied: pyrsistent!=0.17.0,!=0.17.1,!=0.17.2,>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from jsonschema->csvw>=1.5.6->segments->phonemizer==2.2.1->-r requirements.txt (line 5)) (0.18.1)\n",
            "Building wheels for collected packages: librosa, pyopenjtalk\n",
            "  Building wheel for librosa (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
            "  Created wheel for librosa: filename=librosa-0.8.0-py3-none-any.whl size=201396 sha256=63bc2cb9853e17eccdea802e11b0125e140a0f8df9eec123d9b8cd9811cbef97\n",
            "  Stored in directory: /root/.cache/pip/wheels/de/1e/aa/d91797ae7e1ce11853ee100bee9d1781ae9d750e7458c95afb\n"
          ]
        }
      ]
    }
  ]
}